<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>客户价格级别</title>
    <link rel="stylesheet" href="plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="css/comments.css" media="all">
    <style>
        #modifyForm{
            display: none;
            padding: 20px 20px 0 0;
        }
    </style>
</head>
<body>
    <div class="maincontainer">
        <div class="layui-card">
            <div class="layui-card-header layuiadmin-card-header-auto">
                <form id="queryForm" class="layui-form" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">食堂等级</label>
                            <div class="layui-input-inline">
                                <input type="text" name="labelName" autocomplete="off" class="layui-input" placeholder="食堂等级" maxlength="20">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">食堂名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="canteenName" autocomplete="off" class="layui-input" placeholder="食堂名称" maxlength="20">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn"  lay-submit lay-filter="searchBth">查询</button>
                            <button type="reset" class="layui-btn layui-btn-primary" >重置</button>
                        </div>
                    </div>
                </form>
            </div>
            <div class="layui-card-body">
                <table class="layui-hide" id="selectTable" lay-filter="selectTable"></table>
            </div>
        </div>

        <div id="modifyForm">
            <form class="layui-form" action="" lay-filter="modifyForm">
                <div class="layui-form-item">
                    <label class="layui-form-label">食堂等级：</label>
                    <div class="layui-input-block">
                      <input type="text" name="labelName" autocomplete="off" placeholder="请输入食堂等级" class="layui-input" maxlength="20">
                    </div>
                </div>
            </form>
        </div>
    </div>
</body>

<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container toolbarDemo">
		<button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
	</div>
</script>
<script type="text/javascript" src="plugins/layui/layui.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script>
    
    layui.config({
        base: 'plugins/layui/modules/',
    }).use(['http', 'table', 'form', 'laydate'], function() {
        var http = layui.http,
            table = layui.table,
            form = layui.form,
            laydate = layui.laydate;
        var excelList, // 当前页表格数据
            currPage // 当前页码
		
        // 检测供应商是否审核通过
        http.checking(function() {

            // 后台用户列表
            var selectTable;
            selectTable = http.table({
                elem: '#selectTable',
                url: 'supplier/admin/label/listPage',
                method: 'get',
                id: 'selectTable',
                toolbar: '#toolbarDemo',
                done: function(res, curr, count){
                    excelList = res.data;
                    currPage = curr
                },
                cols: [[
                    {title:'序号',type:'numbers',fixed: 'left'}
                    ,{field:'labelName', title: '食堂等级', align : 'center'}
                    ,{field:'relationCanteenCount', title: '关联食堂数', align : 'center'}
                    ,{field:'updateTime', title: '更新时间', align : 'center',width: 170}
                    ,{field:'', title: '操作', align : 'center',fixed: 'right',width: 230,
                        templet: function (d) {
                            var html = '';
                            html += '<button type="button" class="layui-btn layui-btn-primary layui-btn-xs" lay-event="view" >查看关联食堂</button>'
                            html += '<button type="button" class="layui-btn layui-btn-xs" lay-event="modify" >编辑</button>'
                            if(d.relationCanteenCount == 0)
                                html += '<button type="button" class="layui-btn layui-btn-primary layui-btn-xs" lay-event="del" >删除</button>'
                            return html;
                        }
                    }
                ]]
            });

            //查询
            form.on('submit(searchBth)', function (data) {
                let _data = data.field,
                    param = _data;
                selectTable.reload({
                    page:{curr:1},
                    where: param
                })
                return false;
            })

            // table操作
            table.on('tool(selectTable)', function(obj){
                var data = obj.data;
                if(obj.event=='view'){
                    // 查看关联食堂
                    location.href = 'canteenGradeWith.html?id=' + data.id + '&name=' + data.labelName;
                }else if(obj.event=='modify'){
                    // 编辑
                    $('#modifyForm input[name=labelName]').val(data.labelName);
                    http.myOpen({
                        title:'编辑',
                        content: $('#modifyForm'),
                        area:['500px','300px'],
                        btn:['确定','取消'],
                        btn1:function(index, layero){
                            var labelName = $('#modifyForm input[name=labelName]').val()
                            if($.trim(labelName) == ""){
                                layer.msg('请输入食堂等级');
                                return;
                            }
                            http.post('supplier/admin/label/update',{
                                id: data.id,
                                labelName: $.trim(labelName)
                            },function(res){
                                if(res.code == 200){
                                    layer.msg('操作成功')
                                    layer.close(index)
                                    table.reload('selectTable');
                                }else{
                                    layer.msg(res.msg)
                                }
                            })
                            
                        }
                    });
                }else if(obj.event=='del'){
                    // 删除
                    http.myOpen({
                        title:'提示',
                        content:'<p style="text-align:center;margin-top:20px">是否确认删除该食堂等级？</p>',
                        area:['300px','150px'],
                        btn:['确定','取消'],
                        btn1:function(index, layero){
                            http.post('supplier/admin/label/delete',{
                                id: data.id
                            },function(res){
                                if(res.code == 200){
                                    layer.msg('操作成功')
                                    layer.close(index)
                                    table.reload('selectTable');
                                }else{
                                    layer.msg(res.msg)
                                }
                            })
                            
                        }
                    });
                }
            })

            // table的toolbar
            table.on('toolbar(selectTable)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
                var data = checkStatus.data; //获取选中行数据
                if(obj.event=='add'){ 
                    // 添加
                    $("#modifyForm .layui-form")[0].reset();
                    http.myOpen({
                        title:'添加',
                        content: $('#modifyForm'),
                        area:['500px','300px'],
                        btn:['确定','取消'],
                        btn1:function(index, layero){
                            var labelName = $('#modifyForm input[name=labelName]').val()
                            if($.trim(labelName) == ""){
                                layer.msg('请输入食堂等级');
                                return;
                            }
                            http.post('supplier/admin/label/add',{
                                labelName: $.trim(labelName)
                            },function(res){
                                if(res.code == 200){
                                    layer.msg('操作成功')
                                    layer.close(index)
                                    table.reload('selectTable');
                                }else{
                                    layer.msg(res.msg)
                                }
                            })
                            
                        }
                    });
                }
            })
        })

    })

</script>
</html>